package com.winbomb.kingcard.base.anim;

/**
 * Translate Animation
 * 
 * 平移动画
 * 
 * @author winbomb
 * 
 */
public class TransAnimation extends Animation {

	/** 起始坐标 */
	float fromX, fromY;

	/** 终点坐标 */
	float toX, toY;

	/** 当前坐标 */
	float currX, currY;

	/** x/y 轴方向上的速率 */
	float vx, vy;

	public TransAnimation(float fx, float fy, float tx, float ty) {
		this.fromX = fx;
		this.fromY = fy;
		this.toX = tx;
		this.toY = ty;
		this.currX = fromX;
		this.currY = fromY;
		this.vx = 0;
		this.vy = 0;
	}

	public TransAnimation(int fx, int fy, int tx, int ty) {
		this((float) fx, (float) fy, (float) tx, (float) ty);
	}

	public void setDuration(float duration) {
		this.duration = duration;

		this.vx = (toX - fromX) / duration;
		this.vy = (toY - fromY) / duration;
	}

	public void refresh(float dt) {
		this.currX += vx * dt;
		this.currY += vy * dt;
	}

	public float getCurrX() {
		return this.currX;
	}

	public float getCurrY() {
		return this.currY;
	}

	public void clear() {
		this.reset();
		this.fromX = 0;
		this.fromY = 0;
		this.toX = 0;
		this.toY = 0;
		this.currX = 0;
		this.currY = 0;
		this.vx = 0;
		this.vy = 0;
	}

	public void setStart(int fx, int fy) {
		this.fromX = fx;
		this.fromY = fy;
		this.currX = fx;
		this.currY = fy;
	}

	public void setTarget(int tx, int ty) {
		this.toX = tx;
		this.toY = ty;
	}

}
